package com.ngsky.ana.index;

import com.ngsky.ana.comm.AnaResList;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.*;

/**
 * @Author syx
 * @Desc
 * @Create 2020/6/17 9:58
 */
public class HistoryList extends JScrollPane {
    private Frame parent;

    public HistoryList(Frame parent) {
        this.parent = parent;

        // 构建列表
        Box vBox = Box.createVerticalBox();
        vBox.setBackground(Color.ORANGE);
        vBox.setOpaque(true);
        for (int i = 0; i < 200; i++) {
            vBox.add(getItem(i+1));
        }

        setViewportView(vBox);
        setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        getVerticalScrollBar().setUnitIncrement(20);
    }

    private Component getItem(int index) {
        FlowLayout layout = new FlowLayout();
        layout.setAlignOnBaseline(true);
        layout.setAlignment(FlowLayout.LEADING);
        JPanel panel = new JPanel(layout);

        panel.setBorder(BorderFactory.createLineBorder(new Color(153,209,255)));

        // 创建文本框，指定可见列数为8列
        final JLabel timeLab = new JLabel();
        timeLab.setSize(new Dimension(1000, 200));
        timeLab.setText(index + "    2020-12-09 23:22    ");
        timeLab.setFont(new Font(null, Font.PLAIN, 20));

        // 创建文本框，指定可见列数为8列
        final JLabel dirLab = new JLabel();
        dirLab.setSize(new Dimension(1000, 200));
        dirLab.setText("C:\\Users\\Administrator\\Desktop\\2020-06-16");
        dirLab.setFont(new Font(null, Font.PLAIN, 20));

        panel.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent me) {
                System.out.println("历史记录 条目点击...:");
                showAnsResDialog("C:\\Users\\Administrator\\Desktop\\2020-06-10");
            }
        });

        panel.add(timeLab);
        panel.add(dirLab);
        return panel;
    }

    private void showAnsResDialog(String fileDir) {
        AnaResList anaResList = new AnaResList(this.parent, fileDir);
    }
}
